package com.managerConsummer.controller;

import com.alibaba.fastjson.JSON;
import com.managerConsummer.service.StoreServiceFeign;
import entity.ResponseMessage;
import entity.Store;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import util.DownLoadFile;

import javax.servlet.http.HttpServletResponse;

/**
 * 门店控制器
 * The type Store controller.
 *
 * @author tapoliuliyue
 * @date 2022/04/23
 */
@RestController
@RequestMapping("/store")
@CrossOrigin
public class StoreController {

    @Autowired
    private StoreServiceFeign storeServiceFeign;

    private Logger logger = Logger.getLogger(this.getClass());

    /**
     * Select all store string.
     *
     * @param store the store
     * @return the string
     */
    @RequestMapping("/selectAllStore")
    public String selectAllStore(@RequestBody Store store) {
        String s = storeServiceFeign.selectAllStore(store);
        return s;
    }

    /**
     * Update store string.
     *
     * @param store the store
     * @return the string
     */
    @RequestMapping("/updateStore")
    public String updateStore(@RequestBody Store store) {
        String s = storeServiceFeign.updateStore(store);
        return s;
    }

    @RequestMapping("/download/{fileName}")
    public String download(@PathVariable("fileName") String fileName, HttpServletResponse response) {
        ResponseMessage msg = DownLoadFile.downLoadFile(response, fileName);
        return JSON.toJSONString(msg);
    }
}
